import 'package:flutter/services.dart';

/// 读取asset文件夹下面的内容
Future<String> loadAsset(String fileName) async {
  var a = await rootBundle.loadString(fileName);
  return a;
}

/// 将数字转化为汉字，100以内(包含100)
String numberToChinese(int number) {
  const String chineseNumbers = '零一二三四五六七八九十';
  const String chineseUnits = ' 十百';
  String result = '';
  int unitIndex = 0;
  if (number == 0) {
    result = '一';
    return result;
  }
  while (number > 0) {
    int digit = number % 10;
    if (digit != 0 || unitIndex == 0 || result.isNotEmpty) {
      result = chineseNumbers[digit] + chineseUnits[unitIndex] + result;
    }
    unitIndex++;
    number = (number / 10).floor();
  }
  return result.trim();
}

Color getColorFromHex(String hexColor) {
  hexColor = hexColor.replaceAll("#", "");
  if (hexColor.length == 6) {
    hexColor = "FF$hexColor"; // 添加透明度（不透明）
  }
  return Color(int.parse(hexColor, radix: 16));
}
